package day03;

/*
 * Author: JacksonCoder
 * FileName: StreamDemo
 * Version: 1.0.0
 * Date: 2025/4/10
 */

import java.util.*;
import java.util.stream.Collectors;
import java.util.Arrays;

class User {
    private String name;
    private int age;

    // 构造器
    public User(String name, int age){
        this.name = name;
        this.age = age;
    }

    // getter 方法
    public String getName(){
        return name;
    }

    public int getAge(){
        return age;
    }
}

public class StreamDemo {
    public static void main(String[] args) {
        List<User> userList = Arrays.asList(
                new User("alice",15),
                new User("alen",13),
                new User("David",53),
                new User("Nexora",35)
        );


        // 使用 stream 筛选出年龄大于18岁的人，按年龄升序，获取名字列表
        List<String> result = userList.stream()
                .filter(user -> user.getAge() > 18)
                .sorted(Comparator.comparing(User::getAge))
                .map(User::getName)
                .collect(Collectors.toList());

        System.out.println(result); // 输出: []
    }


}
